
package com.example.origin.demo.demo.currentprint;

import java.util.concurrent.locks.LockSupport;

public class AlteratePrint {
    static Thread threadA = null;
    static Thread threadB = null;

    public static void main(String[] args) {

        threadA = new Thread(()->{
            for (int i = 0; i < 100; i++) {
                if (i%2==0){
                    System.out.print(i+" ");
                    LockSupport.unpark(threadB);
                    LockSupport.park();
                }
            }
        });
        threadB = new Thread(()->{
            for (int i = 0; i < 100; i++) {
                if (i%2==1){
                    LockSupport.park();
                    System.out.print(i+" ");
                    LockSupport.unpark(threadA);
                }
            }
        });

        threadA.start();
        threadB.start();


    }
}